var Player = {
	id : null,
	name : '',
	founds : 0,
	sex : 'M',

	card1 : null,
	card2 : null,

	x : 0,
	y : 0,
	width : 212,
	height : 115,
	
	avatarImg : null,
	avatarbgox : 0,
	avatarbgoy : 0,
	
	_myTurn : false,

	init : function(id, name, founds, sex) {
		this.id = id;
		this.name = name;
		this.founds = founds;
		this.sex = sex;

		$g('c').add('player' + id, this);

		this.card1 = jQuery.extend(true, {}, Card);
		this.card1.init(this.x + 100, this.y + 10);
		this.card2 = jQuery.extend(true, {}, Card);
		this.card2.init(this.x + 180, this.y + 10);
		
		this.randomAvatar();
	},
	
	randomAvatar : function() {
		this.avatarImg = Preloader.getImg('avatars.png');
		this.avatarbgox = Math.floor(Math.random()*4)*128;
		this.avatarbgoy = Math.floor(Math.random()*12)*128;
	},

	updateCoords : function(x, y) {
		this.x = x;
		this.y = y;
		/*this.card2.x = x + this.width - Card.width - 10;
		this.card2.y = y + 10;
		this.card1.x = x + this.width - Card.width * 2 - 20;
		this.card1.y = y + 10;*/
		this.card1.updateCoords(x + this.width - Card.width * 2 - 20, y + 10);
		this.card2.updateCoords(x + this.width - Card.width - 10, y + 10);
		
	},
	/*updateCardCoords : function() {
		if (!this.card2.isInStack) {
			this.card2.x = this.x + this.width - Card.width - 10;
			this.card2.y = this.y + 10;
		}
		if (!this.card1.isInStack) {
			this.card1.x = this.x + this.width - Card.width * 2 - 20;
			this.card1.y = this.y + 10;
		}
	},*/
	

	update : function() {

	},

	draw : function(ctx, canvas) {
		ctx.fillStyle = "#663f10";
		ctx.fillRect(this.x + 1, this.y + 1, this.width - 2, this.height - 2);

		ctx.strokeStyle = "#4b2e0c";
		ctx.lineWidth = "2";
		ctx.strokeRect(this.x + 4, this.y + 4, this.width - 8, this.height - 8);
		ctx.strokeStyle = this._myTurn?'#ee1':'#2b0e07';
		ctx.lineWidth = "2";
		ctx.strokeRect(this.x + 1, this.y + 1, this.width - 2, this.height - 2);

		ctx.save();
		ctx.globalCompositeOperation = "source-atop";
		ctx.globalAlpha = 0.15;
		ctx.drawImage(Table.noiseImg, 0,0, this.width, this.height,
				this.x + 1, this.y + 1, this.width - 2, this.height - 2);
		ctx.restore();

		ctx.drawImage(this.avatarImg, this.avatarbgox, this.avatarbgoy,
				128, 128, this.x+12, this.y+12, 72, 72);
		ctx.strokeStyle = "#000";
		ctx.lineWidth = "2";
		ctx.strokeRect(this.x+12, this.y+12, 72, 72);
		

		ctx.font = '20px Geo';
		ctx.fillStyle = "#fff";
		ctx.textAlign = 'end';
		ctx.fillText(this.founds+' zl', this.x+this.width-10, this.y+102, 100);

		ctx.textAlign = 'start';
		ctx.fillText(this.name, this.x+10, this.y+102,100);
		
	},
	
	startTurn : function() {
		this._myTurn = true;
		/*Quene.add(this.id,this,function(){this.card1.show();}, 150);
		Quene.add(this.id,this,function(){this.card2.show();}, 150);*/
	},
	
	endTurn : function() {
		this._myTurn = false;
		/*Quene.add(this.id,this,function(){this.card1.hide();}, 150);
		Quene.add(this.id,this,function(){this.card2.hide();}, 150);*/
	},
	
	startRound : function(delay,max) {
		var multiply = 450;
		delay *= multiply;
		max *= multiply;
		Quene.add(this.id+'1',this,function(){this.card1.moveFromStack();}, delay);
		Quene.add(this.id+'1',this,function(){this.card1.show();}, 350);
		
		Quene.add(this.id+'2',this,function(){this.card2.moveFromStack();}, delay+max);
		Quene.add(this.id+'2',this,function(){this.card2.show();}, 350);
	},
	
	endRound : function(delay,max) {
		var multiply = 550;
		delay *= multiply;
		Quene.add(this.id+'1',this,function(){this.card1.hide();}, delay);
		Quene.add(this.id+'1',this,function(){this.card1.moveToStack();}, 350);
		
		Quene.add(this.id+'2',this,function(){this.card2.hide();}, delay+150);
		Quene.add(this.id+'2',this,function(){this.card2.moveToStack();}, 350);
	}
	
	
};